/*
 * Copyright (c) 2024 Huawei Technologies Co.,Ltd.
 *
 * openGauss is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 * http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * ---------------------------------------------------------------------------------------
 *
 * imcu_storage.h
 * routines to support ColStore
 *
 *
 * IDENTIFICATION
 * src/include/access/imcs/imcu_storage.h
 *
 * ---------------------------------------------------------------------------------------
 */
#ifndef IMCU_STORAGE_H
#define IMCU_STORAGE_H

#include "imcu.h"
#include "storage/smgr/relfilenode.h"
#include "storage/smgr/fd.h"
#include "imcs_allocspace.h"
#include "storage/custorage.h"

class IMCUFile;

class IMCUStorage : public CUStorage {
public:
    IMCUStorage(const CFileNode &cFileNode, CStoreAllocateStrategy strategy = APPEND_ONLY);
    virtual ~IMCUStorage();
    virtual void Destroy();

    friend class IMCUFile;

    /* Write IMCU data into storage */

    void SaveIMCU(_in_ char *write_buf, _in_ int size, _in_ int cu_id, bool direct_flag, bool for_extension = false);

    /* Load IMCU data from storage */

    void LoadIMCU(_in_ IMCU *cu_ptr, _in_ int cu_id, _in_ int size, bool direct_flag, bool in_cu_cache);

    /* remove IMCU file */
    void RemoveImcuFile(_in_ int col, _in_ int cu_id);

    File WSOpenFile(_in_ char *file_name, _in_ int file_id, bool direct_flag);

    void InitFileNamePrefix(_in_ const CFileNode &cFileNode);

private:
    void Load_data(_in_ int size, __inout char *outbuf, _in_ int cu_id, bool direct_flag);
};

/* Notice: the following functions are in physical/low level.
 * 	  they don't know IMCU's concept, and just load data from file.
 */
class IMCUFile : public CUFile {
public:
    IMCUFile(const RelFileNode &file_node, int col);
    virtual void Destroy();
    virtual ~IMCUFile();

private:
    IMCUStorage *m_col_storage;
};

#endif
